package com.dd.stack.jvm.heap;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/8/19 0:10
 * @Description 类功能作用说明
 */
public class OutOfMemoryError {
    public static void main(String[] args) {
        int i = 0;
        try {
            List<String> list = new ArrayList<String>();
            String a = "hello";
            while (true) {
                list.add(a);
                a = a + a;
                i++;
            }
        } catch (Throwable e) {
            e.printStackTrace();
            // -Xmx8m 指定堆内存最大值
            System.out.println(i); // 27
        }
    }
}
